﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:Framework.UI.Controls"
                    xmlns:params="clr-namespace:Elysium.Parameters;assembly=Elysium">
    <ResourceDictionary.MergedDictionaries>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Converter.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Brush.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/FocusVisualStyle.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Controls/TabItem.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/ElysiumExtra/BorderFix.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="{x:Type TabControl}" TargetType="{x:Type TabControl}" >
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource LowlightBrush}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="params:TabControl.IndicatorBrush" Value="{StaticResource HighlightBrush}" />
        <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}" />
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource Self},Path=(params:General.TextFontSize),Mode=OneWay}" />
        <Setter Property="FontStretch" Value="Medium" />
        <Setter Property="FontStyle" Value="Normal" />
        <Setter Property="FontWeight" Value="Normal" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
        <Setter Property="TextOptions.TextRenderingMode" Value="ClearType" />
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" />
        <Setter Property="UIElement.ClipToBounds" Value="True" />
        <Setter Property="FocusVisualStyle" Value="{StaticResource {x:Static SystemParameters.FocusVisualStyleKey}}"/>
        <Setter Property="Focusable" Value="False" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self},Path=(params:General.BoldPadding),Converter={StaticResource ThicknessConverter},ConverterParameter=Top,Mode=OneWay}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <controls:BorderFix Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            TextBlock.Foreground="{TemplateBinding Foreground}" 
                            TextBlock.FontFamily="{TemplateBinding Control.FontFamily}" 
                            TextBlock.FontSize="{TemplateBinding FontSize}" 
                            TextBlock.FontStretch="{TemplateBinding FontStretch}" 
                            TextBlock.FontStyle="{TemplateBinding FontStyle}" 
                            TextBlock.FontWeight="{TemplateBinding FontWeight}" 
                            TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}" 
                            TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}" 
                            RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}" 
                            KeyboardNavigation.DirectionalNavigation="Local" 
                            UIElement.ClipToBounds="{TemplateBinding UIElement.ClipToBounds}" 
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Name="FirstColumnDefinition" Width="*" />
                                <ColumnDefinition x:Name="SecondColumnDefinition" Width="0" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition x:Name="FirstRowDefinition" Height="Auto" />
                                <RowDefinition x:Name="SecondRowDefinition" Height="*" />
                            </Grid.RowDefinitions>
                            <Rectangle x:Name="Indicator" Grid.Column="0" Grid.Row="0" Fill="{TemplateBinding params:TabControl.IndicatorBrush}" Height="{TemplateBinding params:TabControl.IndicatorThickness}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
                            <TabPanel x:Name="HeaderPanel" Grid.Column="0" Grid.Row="0" Panel.IsItemsHost="True" KeyboardNavigation.TabIndex="1" />
                            <Border x:Name="ContentPanel" 
                                        Grid.Column="0" 
                                        Grid.Row="1" 
                                        KeyboardNavigation.DirectionalNavigation="Contained" 
                                        KeyboardNavigation.TabIndex="2" 
                                        KeyboardNavigation.TabNavigation="Local" 
                                        Background="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.Background)}" 
                                        BorderBrush="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.BorderBrush)}" 
                                        BorderThickness="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.BorderThickness)}"
                                        TextBlock.Foreground="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.Foreground)}"
                                        TextBlock.FontFamily="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.FontFamily)}" 
                                        TextBlock.FontSize="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.FontSize)}" 
                                        TextBlock.FontStretch="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.FontStretch)}" 
                                        TextBlock.FontStyle="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.FontStyle)}" 
                                        TextBlock.FontWeight="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.FontWeight)}" 
                                        TextOptions.TextFormattingMode="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TextOptions.TextFormattingMode)}" 
                                        TextOptions.TextRenderingMode="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TextOptions.TextRenderingMode)}" 
                                        RenderOptions.ClearTypeHint="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(RenderOptions.ClearTypeHint)}">
                                <ContentPresenter x:Name="PART_SelectedContentHost" 
                                                              ContentPresenter.ContentSource="SelectedContent" 
                                                              Margin="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.Padding)}" 
                                                              HorizontalAlignment="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.HorizontalContentAlignment),Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" 
                                                              VerticalAlignment="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectedItem.(TabItem.VerticalContentAlignment),Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"/>
                            </Border>
                        </Grid>
                    </controls:BorderFix>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TabControl.TabStripPlacement" Value="Bottom">
                            <Setter TargetName="FirstRowDefinition" Property="Height" Value="*" />
                            <Setter TargetName="SecondRowDefinition" Property="Height" Value="Auto" />
                            <Setter TargetName="Indicator" Property="Grid.Row" Value="1" />
                            <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="1" />
                            <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
                            <Setter TargetName="Indicator" Property="VerticalAlignment" Value="Top" />
                        </Trigger>
                        <Trigger Property="TabControl.TabStripPlacement" Value="Left">
                            <Setter TargetName="FirstColumnDefinition" Property="Width" Value="Auto" />
                            <Setter TargetName="SecondColumnDefinition" Property="Width" Value="*" />
                            <Setter TargetName="FirstRowDefinition" Property="Height" Value="*" />
                            <Setter TargetName="SecondRowDefinition" Property="Height" Value="0" />
                            <Setter TargetName="Indicator" Property="Grid.Column" Value="0" />
                            <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="0" />
                            <Setter TargetName="ContentPanel" Property="Grid.Column" Value="1" />
                            <Setter TargetName="Indicator" Property="Grid.Row" Value="0" />
                            <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0" />
                            <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
                            <Setter TargetName="Indicator" Value="{Binding RelativeSource={RelativeSource Self},Path=(params:TabControl.IndicatorThickness)}" Property="Width" />
                            <Setter TargetName="Indicator" Property="Height" Value="NaN" />
                            <Setter TargetName="Indicator" Property="HorizontalAlignment" Value="Right" />
                            <Setter TargetName="Indicator" Property="VerticalAlignment" Value="Stretch" />
                        </Trigger>
                        <Trigger Property="TabControl.TabStripPlacement" Value="Right">
                            <Setter TargetName="FirstColumnDefinition" Property="Width" Value="*" />
                            <Setter TargetName="SecondColumnDefinition" Property="Width" Value="Auto" />
                            <Setter TargetName="FirstRowDefinition" Property="Height" Value="*" />
                            <Setter TargetName="SecondRowDefinition" Property="Height" Value="0" />
                            <Setter TargetName="Indicator" Property="Grid.Column" Value="1" />
                            <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="1" />
                            <Setter TargetName="ContentPanel" Property="Grid.Column" Value="0" />
                            <Setter TargetName="Indicator" Property="Grid.Row" Value="0" />
                            <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0" />
                            <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
                            <Setter TargetName="Indicator" Value="{Binding RelativeSource={RelativeSource Self},Path=(params:TabControl.IndicatorThickness)}" Property="Width" />
                            <Setter TargetName="Indicator" Property="Height" Value="NaN" />
                            <Setter TargetName="Indicator" Property="HorizontalAlignment" Value="Left" />
                            <Setter TargetName="Indicator" Property="VerticalAlignment" Value="Stretch" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger DataTrigger.Binding="{Binding RelativeSource={RelativeSource Self},Path=FontSize,Mode=OneWay,Converter={StaticResource IsGreaterThanConverter},ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
            </DataTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource DisabledBrush}" />
                <Setter Property="Foreground" Value="{StaticResource DisabledBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>